﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Lime49;

namespace LaunchMeNot.Core {
    /// <summary>
    /// An entry which whose launch status is tracked.
    /// </summary>
    public class  PendingLaunchMeNotEntry : LaunchMeNotEntry {
        protected bool _isLaunched;
        protected double _launchDelayRemaining;
        protected string _errorMessage;

        /// <summary>
        /// Gets or sets the error message raised when the entry was started, or <c>null</c>.
        /// </summary>
        /// <value>The error message raised when the entry was started, or <c>null</c>..</value>
        public string ErrorMessage {
            get { return _errorMessage; }
            set
            {
                _errorMessage = value;
                OnPropertyChanged("ErrorMessage");
            }
        }

        /// <summary>
        /// Gets or sets whether this entry has been launched.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this entry has been launched, otherwise <c>false</c>.
        /// </value>
        public bool IsLaunched
        {
            get { return _isLaunched; }
            set {
                _isLaunched = value;
                OnPropertyChanged("IsLaunched");
            }
        }

        /// <summary>
        /// Gets or sets the number of seconds still remaining before the program launches.
        /// </summary>
        /// <value>The number of seconds still remaining before the program launches>.</value>
        public double LaunchDelayRemaining
        {
            get { return _launchDelayRemaining; }
            set
            {
                _launchDelayRemaining = value;
                OnPropertyChanged("LaunchDelayRemaining");
            }
        }

        /// <summary>
        /// Initializes a new, blank <see cref="PendingLaunchMeNotEntry"/>.
        /// </summary>
        public PendingLaunchMeNotEntry()
            : base() {
                _isLaunched = false;
                _launchDelayRemaining = 0;
        }

        /// <summary>
        /// Initializes a new <see cref="PendingLaunchMeNotEntry"/> from an untracked entry.
        /// </summary>
        public PendingLaunchMeNotEntry(LaunchMeNotEntry entry)
            : base() {
                _id = entry.ID;
                _isEnabled = entry.IsEnabled;
                _launchDelay = entry.LaunchDelay;
                //_launchDelayRemaining = this._launchDelay;
                _launchOrder = entry.LaunchOrder;
                _name = entry.Name;
                _path = entry.Path;
                _arguments = entry.Arguments;
        }

        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>A deep copy of this entry.</returns>
        public override IStartupEntry Clone() {
            var entry = new PendingLaunchMeNotEntry()
            {
                ID = this.ID,
                IsEnabled = this.IsEnabled,
                LaunchOrder = this.LaunchOrder,
                LaunchDelay = this.LaunchDelay,
                LaunchDelayRemaining = this.LaunchDelayRemaining,
                ErrorMessage = this.ErrorMessage,
                Name = this.Name,
                Path = this.Path,
                Arguments = this.Arguments
            };
            return entry;   
        }
    }
}